﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace Project
{
    public class InsertData
    {
      string Connection = ConfigurationManager.ConnectionStrings["DB_UdrinkConnectionString"].ConnectionString;
            public static object GetDataValue(object value)
            {
                if (value == null)
                {
                    return DBNull.Value;
                }

                return value;
            }

            public void InsertsTime(Data DataTime)
            {
                string sqltext = @"insert into TB_Time_Cards 
                                               ([Employee_ID]
                                                ,[Check_in]
                                                ,[Emp_QRcode])
                                               values (@Emp_ID,@Check_In,@Emp_QrCode)";
                SqlCommand sqlcomm = new SqlCommand();
                SqlConnection sqlconn = new SqlConnection(Connection);
                sqlcomm.Connection = sqlconn;
                sqlcomm.CommandType = System.Data.CommandType.Text;
                sqlcomm.CommandText = sqltext;
                sqlcomm.Parameters.AddWithValue("@Emp_ID", GetDataValue(DataTime.Emp_ID));
                sqlcomm.Parameters.AddWithValue("@Check_In", GetDataValue(DataTime.Check_in));
                //sqlcomm.Parameters.AddWithValue("@Check_Out", GetDataValue(DataTime.Check_Out));
                sqlcomm.Parameters.AddWithValue("@Emp_QrCode", GetDataValue(DataTime.QR_Code));
               
                try
                {
                    sqlcomm.Connection.Open();
                    sqlcomm.ExecuteNonQuery();
                }
                catch (Exception)
                {

                    sqlcomm.Connection.Close();
                    sqlcomm.Connection.Dispose();
                }
                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();

            }
        }
    }
